home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++,comp.sys.mac.programmer.help,comp.sys.mac.oop.misc,comp.sys.mac.oop.tcl
- Subject: Re: [Q] Overloading operator ->
- Date: 10 Jan 1996 18:13:53 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan10131353@g7240065.bridge.bst.bls.com>
- References: <mlj-0901960854360001@urals.jpl.nasa.gov>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: mlj@tazboy.jpl.nasa.gov's message of Tue, 09 Jan 1996 08:54:36
- -0800
-
- In article <mlj-0901960854360001@urals.jpl.nasa.gov> mlj@tazboy.jpl.nasa.gov (Mose L. Johnson) writes:
-
- : One of the things I want to do is overload the arrow(->) operator. Here
- : is an example of what I tried and want to do.
-
- : template <class T> class ref<class T>
-
- this should be
- template <class T> class ref
- the <class T> at the end is unnecessary and the compiler should complain
- about it.
-
- : {
- : public:
- : T* operator ->();
- : };
-
- : class tester
- : {
- : public:
- : void member();
- : };
-
- : void main()
-
- this should be
- int main(void)
-
- : {
- : ref<tester *> var;
-
- this should be
- ref<tester> var;
-
- : var->member();
- : }
-
- : When I try to compile this, my compiler gives me an error of:
- : illegal return type for operator->()
-
- There are a couple of things missing like a constructor which takes a
- parameter of type tester* and a attribute of that type in the template class
- Like:
-
- template <class T>
- class ref
- {
- public:
- ref(T* t) : t_(t)
- { }
- T* operator ->()
- { return t_; }
-
- private:
- T* t_;
- };
-
- class tester
- {
- public:
- void member();
- };
-
- int
- main(void)
- {
- ref<tester> var(new tester);
- var->member();
- }
-
- Hope this helps
- Regards
-
- -A.
- --
- | A.Champion |
-